package com.lineage.data.item_etcitem.extra;

import com.lineage.data.cmd.EnchantWeapon;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Random;

public class ProtectionScrollElyos extends ItemExecutor {
  private int a;
  
  public static ItemExecutor get() {
    return new ProtectionScrollElyos();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    if (tgItem.getItem().getType2() != 1 || tgItem.getItem().get_safeenchant() <= -1) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("使用对象错误，请确认清楚。"));
      return;
    } 
    if (tgItem.getItem().getItemId() >= 339 && tgItem.getItem().getItemId() <= 344) {
      if (tgItem.getEnchantLevel() >= 12) {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("已经超过最高强化上限。"));
        return;
      } 
      pc.getInventory().removeItem(item, 1L);
      Random random = new Random();
      EnchantWeapon enchantWeapon = new EnchantWeapon();
      if (random.nextInt(100) <= this.a) {
        enchantWeapon.successEnchant(pc, tgItem, 1);
      } else {
        enchantWeapon.successEnchant(pc, tgItem, -tgItem.getEnchantLevel());
      } 
    } else {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
    } 
  }
  
  public void set_set(String[] set) {
    this.a = Integer.parseInt(set[1]);
  }
}
